package com.wuyou.domain;


import com.wuyou.em.ResultEnum;

public class Result<T> {
    private Integer code;
    private String message;
    private T data;


    //返回正确的
    public static Result OK(){
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getStatus());
        result.setMessage(ResultEnum.SUCCESS.getStatusInfo());
        return result;
    }

    //返回错误的
    public static Result ERROR(){
        Result result = new Result();
        result.setCode(ResultEnum.ERROR.getStatus());
        result.setMessage(ResultEnum.ERROR.getStatusInfo());
        return result;
    }
    public static Result ERROR(String exMsg){
        Result result = new Result();
        result.setCode(ResultEnum.ERROR.getStatus());
        result.setMessage(exMsg);
        return result;
    }

    //其他未知错误的返回状态
    public static Result R(ResultEnum resultEnum){
        Result result = new Result();
        result.setCode(resultEnum.getStatus());
        result.setMessage(resultEnum.getStatusInfo());
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}

